package com.demo;

import com.demo.common.constant.JWTConstants;
import lombok.Builder;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

@SpringBootApplication
@MapperScan(basePackages = "com.demo.mapper")
@EnableAsync // 开启异步
public class DlylServerApplication implements CommandLineRunner {
    @Value("${jwt.secret}")
    public String jwtSecret;

    public static void main(String[] args) {
        SpringApplication.run(DlylServerApplication.class, args);
    }

    @Bean
    public PasswordEncoder passwordEncoder(){
        return new  BCryptPasswordEncoder();
    }

    /**
     * 项目 main 方法执行完成之后再执行的方法
     * @param args
     * @throws Exception
     */
    @Override
    public void run(String... args) throws Exception {
        JWTConstants.JWT_SECRET = this.jwtSecret;
    }
}
